package com.pharmacy.service.impl;


import com.pharmacy.dto.CategoriesAddDto;
import com.pharmacy.dto.CategoriesSelectDto;
import com.pharmacy.dto.CategoriesUpdateDto;
import com.pharmacy.entity.Categories;
import com.pharmacy.mapper.CategoriesMapper;
import com.pharmacy.service.CategoriesService;
import com.pharmacy.vo.CategoriesSelectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoriesServiceImpl implements CategoriesService {

    @Autowired
    private CategoriesMapper categoriesMapper;

    /**
     * 添加分类
     * @param categoriesAddDto
     */
    @Override
    public void addCategories(CategoriesAddDto categoriesAddDto) {

        Categories categories = new Categories();
        BeanUtils.copyProperties(categoriesAddDto,categories);
        categoriesMapper.addCategories(categories);
    }

    /**
     * 删除分类
     * @param id
     */
    @Override
    public void deleteCategories(int id) {
        categoriesMapper.deleteCategories(id);
    }

    /**
     * 查询所有分类
     * @return
     */
    @Override
    public List<CategoriesSelectVo> allSelectCategories(CategoriesSelectDto categoriesSelectDto) {

        List<CategoriesSelectVo> list = categoriesMapper.allSelectCategories(categoriesSelectDto);

        return list;
    }

    /**
     * 修改分类
     * @param categoriesUpdateDto
     */
    @Override
    public void updateCategories(CategoriesUpdateDto categoriesUpdateDto) {
        Categories categories = new Categories();
        BeanUtils.copyProperties(categoriesUpdateDto,categories);

        categoriesMapper.updateCategories(categories);
    }

    /**
     * 根据id查询分类
     * @param id
     * @return
     */
    @Override
    public Categories getById(Integer id) {
        Categories categories = categoriesMapper.getById(id);
        return categories;
    }
}
